<script setup lang="ts">
import type { KnowledgeList, KnowledgeType } from '@/types/consult'
import KnowledgeCard from './KnowledgeCard.vue'
import { ref } from 'vue'
import { getKnowledgePage } from '@/services/consult'
const loading = ref(false)
const finished = ref(false)
const props = defineProps<{
  type: KnowledgeType
}>()
const current = ref(1)
const pageSize = ref(5)

//测试
const list = ref<KnowledgeList>([])

const onLoad = async () => {
  const res = await getKnowledgePage({
    type: props.type,
    current: current.value,
    pageSize: pageSize.value
  })
  console.log(props.type)

  list.value.push(...res.data.rows)
  loading.value = false
  if (res.data.pageTotal <= current.value) {
    finished.value = true
  }
  current.value++
}
</script>

<template>
  <div class="knowledge-list">
    <van-list
      v-model:loading="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <knowledge-card
        v-for="item in list"
        :key="item.id"
        :item="item"
      ></knowledge-card>
    </van-list>
  </div>
</template>

<style lang="scss" scoped>
.knowledge-list {
  padding: 0 15px;
}
</style>
